using System;
using System.Collections.Generic;
using System.Text;
using TaugeLibrary.Interfaces;
using TaugeLibrary.Classes.Abstracts;
using TaugeFramework.Forms;
using System.Windows.Forms;
using TaugeLibrary.Classes;
using System.Data.SqlClient;
using System.Data;
using System.Collections;

namespace TaugeFramework.Classes
{
    class TaugeFramework:ITaugeFramework
    {
        public TaugeFramework() { }
        #region ITaugeFramework Members

        #region form
        public void ShowBusinessUnitForm(ABusinessUnitManager p_unit_mgr)
        {
            frmBusinessUnit fb = new frmBusinessUnit(p_unit_mgr);
            fb.MdiParent= Program.fMain;
            fb.Show();
        }

        public void ShowBusinessUnitListForm(ABusinessUnitManager p_unit_mgr)
        {
            frmList fl = new frmList(p_unit_mgr);
            fl.MdiParent = Program.fMain;
            fl.Show();
        }

        public void ShowForm(Form f)
        {
            f.MdiParent = Program.fMain;
            f.Show();
        }

        public void ShowDialog(Form f)
        {
            f.MdiParent = Program.fMain;
            f.ShowDialog();

        }
        #endregion

        #region encryption

        public string Encrypt(string p_target, string p_key)
        {
            return TaugeEncryption.hrEncrypt(p_target, p_key);
        }

        public string Decrypt(string p_target, string p_key)
        {
            return TaugeEncryption.hrDecrypt(p_target, p_key);
        }

        public int generateCheckSum(params string[] astr)
        {
            return TaugeEncryption.generateCheckSum(astr);
        }

        #endregion

        #region UI
        public void writeUI(object o, ContainerControl f)
        {
            UIManager.writeUI(o, f);
        }

        public void readUI(object o, ContainerControl f)
        {            
            UIManager.readUI(o, f);
        }
        #endregion


        #region user
        public int getActiveUserId()
        {
            return Program.ActiveUser.UserId;
        }

        #endregion

        #region database
        public Database getDatabase(string p_dbtype)
        {
            Database db;
            if (p_dbtype == LibConstants.DBDATA)
                db = Program.dbdata;
            else
                db = Program.dbsys;
            return db;
        }

        public object executeScalar(string p_dbtype,string p_sql)
        {
            return getDatabase(p_dbtype).executeScalar(p_sql);            

        }

        public object executeScalar(string p_dbtype, string p_sql, object p_default)
        {
            return getDatabase(p_dbtype).executeScalar(p_sql, p_default);            
        }

        public SqlDataReader executeReader(string p_dbtype, string p_sql)
        {
            return getDatabase(p_dbtype).executeReader(p_sql);            
            
        }

        public SqlDataReader executeReader(string p_dbtype, SqlCommand p_sc)
        {
            return getDatabase(p_dbtype).executeReader(p_sc);            

            
        }

        public int executeNonQuery(string p_dbtype, string p_sql)
        {
            return getDatabase(p_dbtype).executeNonQuery(p_sql);
        }

        public int[] executeNonQuery(string p_dbtype, List<SqlCommand> p_sc, SqlTransaction p_st)
        {
            return getDatabase(p_dbtype).executeNonQuery(p_sc, p_st);
        }

        public int[] executeNonQuery(string p_dbtype, string[] p_sql, SqlTransaction p_st)
        {
            return getDatabase(p_dbtype).executeNonQuery(p_sql, p_st);
        }

        public int executeNonQuery(string p_dbtype, SqlCommand p_sc)
        {
            return getDatabase(p_dbtype).executeNonQuery(p_sc);
        }

        public int[] executeNonQuery(string p_dbtype, SqlCommand[] p_sc, SqlTransaction p_st, params string[] p_output)
        {
            return getDatabase(p_dbtype).executeNonQuery(p_sc, p_st, p_output);
        }

        public DataTable executeDataTable(string p_dbtype, string p_strsql)
        {
            return getDatabase(p_dbtype).executeDataTable(p_strsql);
        }

        public DataTable executeDataTable(string p_dbtype, SqlCommand p_sc)
        {
            return getDatabase(p_dbtype).executeDataTable(p_sc);
        }

        public void executeTaugeCommand(string p_dbtype,TaugeCommand[] acmd, params string[] p_output)
        {
            getDatabase(p_dbtype).executeTaugeCommand(acmd, p_output);            
        }

        

        public string newTempTable(string p_dbtype)
        {
            return getDatabase(p_dbtype).newTempTable();
        }
        #endregion
        #endregion




    }
}
